<html>

<head>
    <script src="/js/sha3.min.js"
        integrity="sha512-PmGDkK2UHGzTUfkFGcJ8YSrD/swUXekcca+1wWlrwALIZho9JX+3ddaaI9wmmf8PmgDIpMtx6TU8YBJAZS0mPQ=="
        crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<title>Login</title>
<style>
    body {
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
        background-color: #f4f7f9;
    }

    .login {
        background-color: #ffffff;
        width: 400px;
        box-shadow: 0 0 10px 0 rgba(0, 0, 0, 0.1);
        padding: 30px;
        text-align: center;
    }

    input[type="text"],
    input[type="password"] {
        border: none;
        background-color: #f7f7f7;
        padding: 12px 20px;
        margin: 8px 0;
        width: 100%;
        box-sizing: border-box;
        font-size: 16px;
        border-radius: 4px;
        box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.1);
    }

    input[type="submit"] {
        background-color: #3385ff;
        border: none;
        color: #ffffff;
        text-transform: uppercase;
        padding: 15px 20px;
        margin-top: 16px;
        border-radius: 4px;
        font-size: 16px;
        cursor: pointer;
        box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    }

    input[type="submit"]:hover {
        background-color: #3385cc;
    }

    h2 {
        margin-top: 0;
        font-weight: normal;
        font-size: 28px;
    }
</style>
</head>

<body>
    <div class="login">
        <h2>Xunlei Login</h2>
        <form id="form" action="/login" method="POST">
            <input type="text" id="auth_user" name="auth_user" placeholder="Enter your username">
            <br>
            <input type="password" id="auth_password" name="auth_password" placeholder="Enter your password">
            <br>
            <input type="submit" value="Login">
        </form>
    </div>
</body>
<script type="text/javascript">
    const formElement = document.getElementById('form');

    formElement.addEventListener('submit', (event) => {
        event.preventDefault();

        const formData = new FormData(formElement);
        const modifiedData = modifyFormData(formData);

        for (let [name, value] of modifiedData.entries()) {
            formElement.elements[name].value = value;
        }

        formElement.submit();
    });

    function modifyFormData(formData) {
        const modifiedData = new FormData();

        const username = formData.get('auth_user');
        const password = formData.get('auth_password');

        const modifiedUsernameValue = sha3_512(username);
        const modifiedPasswordValue = sha3_512(password);

        modifiedData.append('auth_user', modifiedUsernameValue);
        modifiedData.append('auth_password', modifiedPasswordValue);

        return modifiedData;
    }
</script>

</html>